import http from '../utils/http';

/**
 * 根据会议室ID获取评论信息
 * @param {number} roomId - 会议室ID
 * @returns {Promise<AjaxResult>} 返回评论列表数据
 * @typedef {Object} AjaxResult
 * @property {number} code - 状态码 200成功，500失败
 * @property {string} msg - 提示信息
 * @property {Array<Comment>} data - 评论数据
 */
export const getCommentsByRoomId = async (roomId) => {
  try {
    const response = await http.get(`/comments/room/${roomId}`);
    return response.data;
  } catch (error) {
    throw error;
  }
};

/**
 * 保存评论信息
 * @param {Object} commentData - 评论数据
 * @param {number} commentData.orderId - 订单ID
 * @param {number} commentData.roomId - 会议室ID
 * @param {string} commentData.content - 评论内容
 * @param {number} commentData.rating - 评分 (1-5分)
 * @returns {Promise<AjaxResult>} 返回保存结果
 */
export const saveCommentAfterOrder = async (commentData) => {
  try {
    const response = await http.post('/comments/after-order', commentData);
    return response.data;
  } catch (error) {
    throw error;
  }
};

/**
 * 获取所有评论信息
 * @returns {Promise<AjaxResult>} 返回所有评论列表数据
 */
export const getAllComments = async () => {
  try {
    const response = await http.get('/comments');
    return response.data;
  } catch (error) {
    throw error;
  }
};
